const { sequelize, DataTypes } = require('../utill/getSequelize')



//试卷表
const T_exam_paper = sequelize.define('T_exam_paper', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },

  //试卷名称
  paper_name: {
    type: DataTypes.STRING,
    allowNull: false,
  },


  //标记
  t_user_and_a_c_s_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
  },

  //学期
  term: {
    type: DataTypes.STRING,
  },

  //学年
  academy_yaer: {
    type: DataTypes.STRING,
  },

  //学院
  academy: {
    type: DataTypes.STRING
  },

  //开卷，闭卷
  format: {
    type: DataTypes.STRING
  },

  type_paper: {
    //AB卷
    type: DataTypes.STRING,
  },





  subject_id: {//学科
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0
  },



  //分数
  score: {
    type: DataTypes.INTEGER,
    defaultValue: 100
  },

  temScore: {
    type: DataTypes.INTEGER,
  },

  class: {
    type: DataTypes.STRING
  },

  //按答题算
  question_count: {//题目数量
    type: DataTypes.INTEGER,

  },

  suggest_time: {//建议时长(分钟)
    type: DataTypes.INTEGER,
  },



  deleted: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
  },

});



const T_exam_paper_to_question = sequelize.define('T_exam_paper_to_question', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },

  paper_id: {
    type: DataTypes.INTEGER,
  },

  question_id: {
    type: DataTypes.INTEGER,
  },

  question_num: {
    type: DataTypes.INTEGER
  }

});

const { T_exam_question } = require('./t_exam_question');

T_exam_paper_to_question.belongsTo(T_exam_question, {
  foreignKey: 'question_id',
  targetKey: 'id',
});
T_exam_paper_to_question.belongsTo(T_exam_paper, {
  foreignKey: 'paper_id',
  targetKey: 'id',
});

//同步模型和数据库表
(async () => {
  try {
    await sequelize.sync({ force: false });
    console.log('All models were synchronized successfully.');
  } catch (error) {
    console.log(error);
  }

})();

//提供出去
module.exports = { T_exam_paper, T_exam_paper_to_question };